package ji.sky.commonintents;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.provider.AlarmClock;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

import java.util.ArrayList;
import java.util.List;

public class AlarmClockActivity extends AppCompatActivity {
    private Spinner spin_hour;
    private Spinner spin_minutes;
    private Button btn_create_alarm;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm_clock);
        init_widgets();
    }

    protected void init_widgets(){
        spin_hour = findViewById(R.id.spin_hour);
        spin_minutes = findViewById(R.id.spin_minutes);
        btn_create_alarm = findViewById(R.id.btn_create_alarm);

        spin_hour.setSelection(0);
        spin_minutes.setSelection(0);

        btn_create_alarm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String message = "测试闹钟";
                int hour = spin_hour.getSelectedItemPosition();
                int minutes = spin_minutes.getSelectedItemPosition();
                createAlarm(message, hour, minutes);
            }
        });
    }
    // 设置闹钟
    public void createAlarm (String message, int hour, int minutes) {
        Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
        intent.putExtra(AlarmClock.EXTRA_MESSAGE, message);
        intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
        intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
        if (intent.resolveActivity(getPackageManager()) != null)
            startActivity(intent);
    }
}